package com.dcw.lixb.designmode.builder;

import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lixiaobin
 * @date 2020-07-16 18:02:16
 * @desc 餐/套餐
 */

public class Meal {
    private List<Item> items = new ArrayList<Item>();

    public void addItem(Item item){
        items.add(item);
    }

    public float getCost(){
        float cost = 0.0f;
        for (Item item : items) {
            cost += item.price();
        }
        return cost;
    }

    public void showItems(){
        for (Item item : items) {
            System.out.print("Item : "+item.name());
            System.out.print(", Packing : "+item.packing().pack());
            System.out.println(", Price : "+item.price());
        }
    }

    public static class Builder{
        private Meal mMeal;

        public Builder addItem(Item item) {
            if (null == mMeal) {
                mMeal = new Meal();
            }
            mMeal.addItem(item);
            return this;
        }

        public Meal build() {
            if (null == mMeal) {
                mMeal = new Meal();
            }
            return mMeal;
        }
    }
}
